package com.klikmee.sms.core.base.test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import org.dbunit.DatabaseUnitException;
import org.dbunit.database.DatabaseConnection;
import org.dbunit.database.IDatabaseConnection;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:test-context.xml"})
public class ExportTestData {
	
	@Autowired
	@Qualifier("mysqlDataSource")
	private DataSource dataSource;
	
	@Test
	public void testExportData() throws SQLException, DatabaseUnitException, Exception, IOException{
		Connection connection = this.dataSource.getConnection();
		IDatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
		
		String exportFilePath = "smscore_test_full.xml";
		IDataSet dataSet = dbUnitConnection.createDataSet();
		FlatXmlDataSet.write( dataSet, new FileOutputStream( exportFilePath ) );
		
		Assert.assertTrue( 1 == 1 );
	}
}
